package com.grpc_server;
/*

                  写字楼里写字间，写字间里程序员；
                  程序人'猿'写程序，又拿程序换酒钱。
                  酒醒只在网上坐，酒醉还来网下眠；
                  酒醉酒醒日复日，网上网下年复年。
                  但愿老死电脑间，不愿鞠躬老板前；
                  奔驰宝马贵者趣，公交自行程序员。
                  别人笑我忒疯癫，我笑自己命太贱；
                  不见满街漂亮妹，哪个归得程序'猿'？
━━━━━━神兽出没━━━━━━
 ┏┓   ┏┓
┏┛┻━━━┛┻┓
┃       ┃
┃   ━   ┃
┃ ┳┛ ┗┳ ┃
┃       ┃
┃   ┻   ┃
┃       ┃
┗━┓   ┏━┛
  ┃   ┃                    神兽保佑, 永无BUG!
  ┃   ┃       Code is far away from bug with the animal protecting
  ┃   ┗━━━┓
  ┃       ┣┓
  ┃       ┏┛
  ┗┓┓┏━┳┓┏┛
   ┃┫┫ ┃┫┫
   ┗┻┛ ┗┻┛
 */

import com.grpc_server.grpc_netty.GrpcNetService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ImportResource;

import javax.annotation.Resource;

/**
 * Created by 石头哥哥 on 1/12/16.
 * <p>
 * grpc
 * <p>
 * server
 * <p>
 * comments:
 */
@SpringBootApplication
@ImportResource("file:res/spring-grpc.xml")
public class RpcApplicationServer {

    @Resource
    private GrpcNetService grpcNetService;

    /**
     * Main launches the server from the command line.
     */
    public static void main(String[] args) throws Exception {

        // init spring boot
        ConfigurableApplicationContext configurableApplicationContext =
                SpringApplication.run(RpcApplicationServer.class, args);
        //get handle bean
        RpcApplicationServer rpcApplicationServer =
                (RpcApplicationServer) configurableApplicationContext.getBean("rpcApplicationServer");
        //start rpc service
        rpcApplicationServer.grpcNetService.startGrpc();
        //wait termination
        rpcApplicationServer.grpcNetService.awaitTermination();

    }
}
